local fanhua = fk.CreateSkill {
  name = "th_fanhua",
}

fanhua:addEffect(fk.EventPhaseProceeding, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(fanhua.name) and target.phase == Player.Finish
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if #room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
      for _, move in ipairs(e.data) do
        if move.from == player then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand then
              return true
            end
          end
        end
      end
    end, Player.HistoryTurn) == 0 then return false end
    local ret = room:askToUseVirtualCard(player, {
      name = "slash",
      skill_name = fanhua.name,
      prompt = "#th_fanhua-use",
      extra_data = {
        bypass_times = true,
      },
      skip = true
    })
    if ret then
      event:setCostData(self, ret)
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:useCard(event:getCostData(self))
  end,
})
fanhua:addEffect("targetmod", {
  bypass_distances = function(self, player, skill, card, to)
    return card and to and table.contains(card.skillNames, fanhua.name) and to == Fk:currentRoom().current
  end
})

Fk:loadTranslationTable{
  ["th_fanhua"] = "繁花",
  [":th_fanhua"] = "一名角色的结束阶段，若你本回合失去过手牌，你可以视为使用一张【杀】（对其使用无距离限制）。",

  ["#th_fanhua-use"] = "繁花：你可以视为使用一张【杀】",
}

return fanhua